#This file is part of SocialBlast, an application for updating many social services at once.
#Copyright (C) 2007  Jon Bohlinger, Mike Bruder, Jon Mierow, Thomas Knoll, Jason DeBoer-Moran

#SocialBlast is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 2
#of the License, or (at your option) any later version.

#SocialBlast is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import wx
import os

# Retrieve user data
file = open("soc_auth", "r")
user_data = file.readlines()
file.close()
i = 0
for user in user_data:
	user_data[i] = user[:-1]
	i += 1

# Services tab class

class ServicesPage(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        # Twitter settings
        twittertitle = wx.StaticText(self, -1, "Twitter", (20,20))
        twittertitle.SetFont(wx.Font(10, wx.SCRIPT, wx.NORMAL , wx.BOLD))
        wx.StaticText(self, -1, 'Username: ', (20,40))
        wx.StaticText(self, -1, 'Password: ', (20,70))
        self.tnameBox = wx.TextCtrl(self, -1, user_data[4], (120,40), wx.Size(120,-1))
        self.tpasswordBox = wx.TextCtrl(self, -1, user_data[5], (120,70), wx.Size(120,-1), style=wx.TE_PASSWORD)
        # Jaiku settings
        jaikutitle = wx.StaticText(self, -1, "Jaiku", (20,120))
        jaikutitle.SetFont(wx.Font(10, wx.SCRIPT, wx.NORMAL, wx.BOLD))
        wx.StaticText(self, -1, 'Username: ', (20,140))
        wx.StaticText(self, -1, 'API Key: ', (20,170))
        self.jnameBox = wx.TextCtrl(self, -1, user_data[0], (120,140), wx.Size(120,-1))
        self.jpasswordBox = wx.TextCtrl(self, -1, user_data[1], (120,170), wx.Size(120,-1), style=wx.TE_PASSWORD)
        # Facebook settings
        fbtitle = wx.StaticText(self, -1, "Facebook", (260,20))
        fbtitle.SetFont(wx.Font(10, wx.SCRIPT, wx.NORMAL, wx.BOLD))
        wx.StaticText(self, -1, 'E-mail address: ', (260,40))
        wx.StaticText(self, -1, 'Password: ', (260,70))
        self.fbnameBox = wx.TextCtrl(self, -1, user_data[6], (370,40), wx.Size(120,-1))
        self.fbpasswordBox = wx.TextCtrl(self, -1, user_data[7], (370,70), wx.Size(120,-1), style=wx.TE_PASSWORD)
        # Tumblr settings
        trtitle = wx.StaticText(self, -1, "Tumblr", (260,120))
        trtitle.SetFont(wx.Font(10, wx.SCRIPT, wx.NORMAL, wx.BOLD))
        wx.StaticText(self, -1, 'E-mail address: ', (260,140))
        wx.StaticText(self, -1, 'Password: ', (260,170))
        self.trnameBox = wx.TextCtrl(self, -1, user_data[2], (370,140), wx.Size(120,-1))
        self.trpasswordBox = wx.TextCtrl(self, -1, user_data[3], (370,170), wx.Size(120,-1), style=wx.TE_PASSWORD)
        # Buttons
        self.Button1 = wx.Button(self, wx.ID_SAVE,     ' Save ', (200,250), wx.DefaultSize).SetDefault() # The SAVE button
        wx.EVT_BUTTON(self, -1, self.SaveButton) # Associate the button with an event
        
        
    def SaveButton(self, event): #Get the username and password when the SaveButton is clicked, and save it to a file
        tusername = self.tnameBox.GetValue()
        tpassword = self.tpasswordBox.GetValue()
        jusername = self.jnameBox.GetValue()
        jpassword = self.jpasswordBox.GetValue()
        fbusername = self.fbnameBox.GetValue()
        fbpassword = self.fbpasswordBox.GetValue()
        trusername = self.trnameBox.GetValue()
        trpassword = self.trpasswordBox.GetValue()
        outfile = open("soc_auth", "w")
        outfile.write(jusername + "\n" + jpassword + "\n" + trusername + "\n" + trpassword + "\n" + tusername + "\n" + tpassword + "\n" + fbusername + "\n" + fbpassword + "\n")
        outfile.close()
#Add additional classes here to create tabs for each service

class ShortURLPage(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        t = wx.StaticText(self, -1, "This is the URL Shortening tab", (40,40))

#class Service3Page(wx.Panel):
#    def __init__(self, parent):
#        wx.Panel.__init__(self, parent)
#        t = wx.StaticText(self, -1, "This is a Service3Page object", (60,60))


class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Social Blast Settings", size=(500,350))

        # Here we create a panel and a notebook on the panel
        p = wx.Panel(self)
        nb = wx.Notebook(p)

        # create the page windows as children of the notebook
        tab1 = ServicesPage(nb)
        tab2 = ShortURLPage(nb)
        #page3 = Service3Page(nb)

        # add the pages to the notebook with the label to show on the tab
        nb.AddPage(tab1, "Services")
        nb.AddPage(tab2, "URL Shortening")
        #nb.AddPage(tab3, "Service 3")

        # finally, put the notebook in a sizer for the panel to manage
        # the layout
        sizer = wx.BoxSizer()
        sizer.Add(nb, 1, wx.EXPAND)
        p.SetSizer(sizer)


if __name__ == "__main__":
    app = wx.App()
    MainFrame().Show()
    app.MainLoop()
